package com.zjitc;

import java.util.List;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/29 14:07
 * @description:
 */
@Configuration
@ComponentScan(basePackageClasses = MyWebMvcConfiguration.class)
public class MyWebMvcConfiguration extends WebMvcConfigurationSupport {

  /**
   * 	protected final List<HttpMessageConverter<?>> getMessageConverters() {
           if (this.messageConverters == null) {
           this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
           configureMessageConverters(this.messageConverters);
           if (this.messageConverters.isEmpty()) {
              addDefaultHttpMessageConverters(this.messageConverters);
           }
              extendMessageConverters(this.messageConverters);
           }
           return this.messageConverters;
      }
   * @param converters
   */
  @Override
  protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    for (HttpMessageConverter converter : converters) {
      if (converter instanceof GsonHttpMessageConverter) {
        GsonHttpMessageConverter gsonHttpMessageConverter = (GsonHttpMessageConverter) converter;
        gsonHttpMessageConverter.setGson(GsonOfDate.getInstance());
      }
    }
  }
}
